from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import os

# 找到iframe下h3标签,找不到,会报错
driver = webdriver.Chrome()
path = os.path.join(os.path.abspath('html'),'frame.html')
driver.get(path)
# h3 = driver.find_element(By.ID,'inner_h3')
# print(h3.text)


a = driver.find_element(By.ID,'f1') #找到iframe的标签
driver.switch_to.frame(a)#切换到第一个iframe
input1=driver.find_element(By.ID,'inner_h3')
print(input1.text)

#切换到f2  注意不能跳个f1直接切到f2
b =driver.find_element(By.ID,'f2')
driver.switch_to.frame(b)
print(b.id)

# 从f2切换到父类
driver.switch_to.parent_frame()
print(input1.text)


driver.switch_to.default_content()
print(driver.find_element(By.XPATH, '//h3'))










time.sleep(2)
driver.quit()




